package reverseVowels;

public class Solution {
    public String reverseVowels(String s) {
        // 双指针
        int i = 0,j = s.length()-1;
        char[] chars = s.toCharArray();
        while (i<j) {
            if(!check(chars[i])) {
                i++;
            } else if (!check(chars[j])) {
                j--;
            } else {
                swap(chars,i,j);
                i++;
                j--;
            }
        }
        return new String(chars);
    }
    private void swap(char[] s,int i,int j) {
        char t = s[i];
        s[i] = s[j];
        s[j] = t;
    }
    private boolean check(char c) {
        return c == 'a'||
                c == 'e'||
                c == 'o'||
                c == 'i'||
                c == 'u'||
                c == 'A'||
                c == 'E'||
                c == 'O'||
                c == 'I'||
                c == 'U';
    }
}
